import * as path from 'path';
import * as fs from 'fs';
import { parse } from 'yaml';

// 获取项目运行环境
export const getEnv = () => {
  return process.env.NODE_ENV || 'prod';
};

export interface AppConfig {
  [key: string]: unknown;
}

// 读取项目配置
export const getConfig = (): AppConfig => {
  const environment = getEnv();
  const yamlPath = path.join(process.cwd(), `./.config/.${environment}.yaml`);
  const file = fs.readFileSync(yamlPath, 'utf8');
  const config = parse(file) as AppConfig;
  return config;
};
